package core;

import javax.swing.JFrame;

public class QAMConstelationEncoder extends UnitAbstract {


	
	public QAMConstelationEncoder(){
		inputs = new String[]{"1"};
		outputs = new String[]{"I","Q"};
	}

	public void read(DataPackage dataPack, String tPort) {
		DataPackage dataPack0 = dataPack.clone();
		DataPackage dataPack1 = dataPack.clone();
	
		
	        
	        
        for(int i=0; i<dataPack0.data.length; i++){
        	dataPack0.data[i] = mapping(((int) Math.round((dataPack.data[i]+1)*7.5))/4);
        	dataPack1.data[i] = mapping(((int) Math.round((dataPack.data[i]+1)*7.5))%4);
        }
        sendData(dataPack0,outputs[0]);
        sendData(dataPack1,outputs[1]);
	}


	
	private double mapping(int d) {
		switch(d){
		case 0:
			return 1;
		case 1:
			return 3;
		case 2:
			return -1;
		}
		return -3;
	}
	


	@Override
	public JFrame getFrame() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String toString() {
		return "Encoder QAM16";
	}
}
